package com.ruoyi.tsjData.service.impl;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.concurrent.Future;
import java.util.stream.Collectors;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.tsjData.domain.plat.DataTshjKxch;
import com.ruoyi.tsjData.mapper.DataTshjKxchMapper;
import com.ruoyi.tsjData.service.IDataTshjKxchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.AsyncResult;
import org.springframework.stereotype.Service;


/**
 * 提升机-空行程测试Service业务层处理
 * 
 * @author ruoyi
 * @date 2023-10-25
 */
@Service
public class DataTshjKxchServiceImpl implements IDataTshjKxchService
{
    @Autowired(required = false)
    private DataTshjKxchMapper dataTshjKxchMapper;

    /**
     * 查询提升机-空行程测试
     * 
     * @param kxchId 提升机-空行程测试主键
     * @return 提升机-空行程测试
     */
    @Override
    public DataTshjKxch selectDataTshjKxchByKxchId(Long kxchId)
    {
        return dataTshjKxchMapper.selectDataTshjKxchByKxchId(kxchId);
    }

    /**
     * 空行程测试数据
     * @param dataTaskId
     * @return
     */
    @Override
    @Async("threadPoolKy")
    public Future<List<DataTshjKxch>> selectKxch(Long dataTaskId) {
        List<DataTshjKxch> kxchList = dataTshjKxchMapper.selectDataTshjKxchByDataTaskId(dataTaskId);
        List<DataTshjKxch> kxchSortList = new ArrayList<>();
        if (!kxchList.isEmpty()) {
            kxchSortList = kxchList.stream().sorted(Comparator.comparing(DataTshjKxch::getZhaIndex)).collect(Collectors.toList());
        }
        return new AsyncResult<>(kxchSortList);
    }

    /**
     * 查询提升机-空行程测试
     *
     * @param dataTaskId 提升机-空行程测试任务id
     * @return 提升机-空行程测试
     */
    @Override
    public List<DataTshjKxch> selectDataTshjKxchByDataTaskId(Long dataTaskId) {
        return dataTshjKxchMapper.selectDataTshjKxchByDataTaskId(dataTaskId);
    }

    /**
     * 查询提升机-空行程测试列表
     * 
     * @param dataTshjKxch 提升机-空行程测试
     * @return 提升机-空行程测试
     */
    @Override
    public List<DataTshjKxch> selectDataTshjKxchList(DataTshjKxch dataTshjKxch)
    {
        return dataTshjKxchMapper.selectDataTshjKxchList(dataTshjKxch);
    }

    /**
     * 新增提升机-空行程测试
     * 
     * @param dataTshjKxch 提升机-空行程测试
     * @return 结果
     */
    @Override
    public int insertDataTshjKxch(DataTshjKxch dataTshjKxch)
    {
        dataTshjKxch.setCreateTime(DateUtils.getNowDate());
        return dataTshjKxchMapper.insertDataTshjKxch(dataTshjKxch);
    }

    /**
     * 批量新增空行程
     * @param dataTshjKxchs 提升机-空行程测试
     * @return
     */
    @Override
    public int batchDataTshjKxch(List<DataTshjKxch> dataTshjKxchs) {
        return dataTshjKxchMapper.batchDataTshjKxch(dataTshjKxchs);
    }

    /**
     * 修改提升机-空行程测试
     * 
     * @param dataTshjKxch 提升机-空行程测试
     * @return 结果
     */
    @Override
    public int updateDataTshjKxch(DataTshjKxch dataTshjKxch)
    {
        dataTshjKxch.setUpdateTime(DateUtils.getNowDate());
        return dataTshjKxchMapper.updateDataTshjKxch(dataTshjKxch);
    }

    /**
     * 批量修改提升机-空行程测试
     * @param dataTshjKxchs 提升机-空行程测试
     * @return
     */
    @Override
    public int updateBatchDataTshjKxch(List<DataTshjKxch> dataTshjKxchs) {
        return dataTshjKxchMapper.batchDataTshjKxch(dataTshjKxchs);
    }

    /**
     * 空行程测试
     * @param dataTaskIds 速度测试任务id
     * @return
     */
    @Override
    public int updateDataTshjKxchByDataTaskIds(Long[] dataTaskIds) {
        return dataTshjKxchMapper.updateDataTshjKxchByDataTaskIds(dataTaskIds);
    }

    /**
     * 变更空行程测试状态为2
     * @param dataTaskId
     * @param kxchId
     * @return
     */
    @Override
    public int updateDataTshjKxchByKxchId(Long dataTaskId, Long kxchId) {
        return dataTshjKxchMapper.updateDataTshjKxchByKxchId(dataTaskId, kxchId);
    }

    /**
     * 批量删除提升机-空行程测试
     * 
     * @param kxchIds 需要删除的提升机-空行程测试主键
     * @return 结果
     */
    @Override
    public int deleteDataTshjKxchByKxchIds(Long[] kxchIds)
    {
        return dataTshjKxchMapper.deleteDataTshjKxchByKxchIds(kxchIds);
    }

    /**
     * 删除提升机-空行程测试信息
     * 
     * @param kxchId 提升机-空行程测试主键
     * @return 结果
     */
    @Override
    public int deleteDataTshjKxchByKxchId(Long kxchId)
    {
        return dataTshjKxchMapper.deleteDataTshjKxchByKxchId(kxchId);
    }
}
